﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VSSDK.Tools.VsIdeTesting;
using EnvDTE80;
using EnvDTE;
using System.IO;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Tests.Integration.Instruments
{
    public static class SolutionManager
    {
        public static void OpenSolution(string path)
        {
            var solution = VsIdeTestHostContext.Dte.Solution;
            solution.Close(false);
            solution.Open(path);
        }

        //public static void SelectProject(string name)
        //{
        //    var solutionExplorer = VsIdeTestHostContext.Dte.Windows.Item("{3AE79031-E1BC-11D0-8F78-00A0C9110057}");
        //    var solutionTree = solutionExplorer.Object as UIHierarchy;
        //    solutionTree.GetItem(name).Select(vsUISelectionType.vsUISelectionTypeSelect);
        //    solutionExplorer.Activate();
        //}

        public static void SelectProjects(params string[] names)
        {
            var solutionExplorer = VsIdeTestHostContext.Dte.Windows.Item("{3AE79031-E1BC-11D0-8F78-00A0C9110057}");
            var solutionTree = solutionExplorer.Object as UIHierarchy;
            solutionTree.GetItem(Path.GetFileNameWithoutExtension(VsIdeTestHostContext.Dte.Solution.FullName)).Select(vsUISelectionType.vsUISelectionTypeSelect);
            solutionTree.GetItem(Path.GetFileNameWithoutExtension(VsIdeTestHostContext.Dte.Solution.FullName)).Select(vsUISelectionType.vsUISelectionTypeToggle);
            foreach (var name in names)
            {
                solutionTree.GetItem(name).Select(vsUISelectionType.vsUISelectionTypeToggle);
                //solutionTree.GetItem(name).Select(vsUISelectionType.vsUISelectionTypeSelect);
            }
            solutionExplorer.Activate();
        }
    }
}
